﻿<%@ WebHandler Language="C#" Class="YPOrderContainerStartHandler" %>

using System;
using System.Web;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using System.Linq;
using BusinessRule.Business;
using System.Data;
using Newtonsoft.Json;
using System.IO;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.HSSF.UserModel;
using System.Collections;
using BusinessRule.DTO;
using System.Web.SessionState;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;
using Camstar.WebClient.WebServicesProxy.InSiteWebServices;


//Description:多订单批量开卡处理程序
//Copyright (c) : 通力凯顿（北京）系统集成有限公司
//Writer:zhangrj
//create Date:2022-01-12
public class YPOrderContainerStartHandler : IHttpHandler, IRequiresSessionState
{
    uLMSCommonIBusiness m_CommonObj = uMESBusinessFactory.instance.GetuLMSCommonObject();
    uLMSContainerIBusiness m_ContainerObj = uMESBusinessFactory.instance.GetuLMSContainerObject();
    YPCommonBusiness ypCommon = new YPCommonBusiness();
    uLMSSendDataToWmsBusiness wms = new uLMSSendDataToWmsBusiness();
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            var action = context.Request.Form["action"].ToString();
            switch (action)
            {
                case "GetContainerBaseInfo"://获取基于批次创建的数据
                    GetContainerBaseInfo(context);
                    break;
                case "GetWorkFlowListDatas":
                    GetWorkFlowListDatas(context);
                    break;
                case "GetStepListDatas":
                    GetStepListDatas(context);
                    break;
                case "GetTeams":
                    GetTeams(context);
                    break;
                case "GetProductFamily":
                    GetProductFamily(context);
                    break;
                case "SaveContainerData":
                    SaveContainerData(context);
                    break;
                default:
                    break;
            }
        }
        catch (Exception e)
        {
            context.Session.Remove("BatchOrderContainerDT");
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Message = "出错了：" + e.Message, Result = false }));
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    /// <summary>
    /// 初始化页面数据
    /// </summary>
    /// <param name="context"></param>
    public void GetContainerBaseInfo(HttpContext context)
    {
        CurrentUserInfo m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
        DataTable orderContainers = (DataTable)context.Session["BatchOrderContainerDT"];
        context.Session.Remove("BatchOrderContainerDT");
        if (m_UserInfo == null || orderContainers.Rows.Count == 0)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Message = "系统缓存已过期，请刷新页面", Result = false }));
            return;
        }
        DataSet dtset = new DataSet();
        //多订单批次数据
        orderContainers.TableName = "orderContainers";
        dtset.Tables.Add(orderContainers);
        string ProductName = orderContainers.Rows[0]["productName"].ToString();
        string ProductID = orderContainers.Rows[0]["productID"].ToString();
        string ProductRev = orderContainers.Rows[0]["productRev"].ToString();
        string WorkFlowName = orderContainers.Rows[0]["WorkFlowName"].ToString();
        string WorkFlowID = orderContainers.Rows[0]["WorkflowID"].ToString();
        //获取件号下拉数据
        DataTable subSectionProduct = m_CommonObj.GetSubsectionProductInfo(ProductName, ProductID);
        DataTable subSectionProduct_dt = subSectionProduct.DefaultView.ToTable(false, new string[] { "productname", "productid" });
        DataRow subSectionProduct_dr = subSectionProduct_dt.NewRow();
        subSectionProduct_dr["productname"] = ProductName + ":" + ProductRev;
        subSectionProduct_dr["productid"] = ProductID;
        subSectionProduct_dt.Rows.InsertAt(subSectionProduct_dr, 0);//将默认的版本放入第一行
        subSectionProduct_dt.TableName = "subSectionProductDt";
        dtset.Tables.Add(subSectionProduct_dt);
        //获取工艺路线下拉数据
        Dictionary<string, string> para = new Dictionary<string, string>();
        para.Add("ProductName", ProductName);
        para.Add("ProductID", ProductID);
        para.Add("WorkFlowName", WorkFlowName);
        para.Add("ProductRev", ProductRev);
        para.Add("FactoryID", m_UserInfo.FactoryID);
        DataTable wfdata = m_CommonObj.GetWorkflowInfoWithOtherAndSubByProductInfo(para, false, true);
        wfdata.TableName = "sectionWorkFlowDt";
        dtset.Tables.Add(wfdata);
        //获取工序下拉数据
        //DataTable stepTable = m_CommonObj.GetWorkFlowSetpsByWorkflowID(WorkFlowID);
        //stepTable.TableName = "sectionStepDt";
        //dtset.Tables.Add(stepTable);
        //获取主制工区下拉数据
        DataTable wcdt = m_CommonObj.GetWorkCenterByFacoryID(m_UserInfo.FactoryID, false);
        wcdt.TableName = "sectionWcDt";
        dtset.Tables.Add(wcdt);
        //获取工艺员下拉数据
        DataTable employeedt = m_CommonObj.GetEmplyeeListByRole("工艺员", m_UserInfo.FactoryID);
        string strFactoryValue = m_CommonObj.GetFatoryAttributes(m_UserInfo.FactoryID, "工序关联工区班组"); //获取工厂是否工序关联工区班组
        DataRow[] newdr = employeedt.Select();
        DataTable ChildWFTechniquedt = newdr.CopyToDataTable();
        if (strFactoryValue == "是" && !string.IsNullOrWhiteSpace(m_UserInfo.WorkCenterID))
        {
            if (!String.IsNullOrWhiteSpace(m_UserInfo.WorkCenterID))
            {
                DataView dv = employeedt.DefaultView;
                dv.RowFilter = String.Format("WORKCENTERID='{0}'", m_UserInfo.WorkCenterID);
                employeedt = dv.ToTable();
            }
        }
        employeedt.TableName = "sectionEmployDt";
        dtset.Tables.Add(employeedt);
        //获取单位下拉数据
        DataTable dt_UOM = m_CommonObj.GetUom();
        dt_UOM.TableName = "sectionUOMDt";
        dtset.Tables.Add(dt_UOM);
        context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Message = "获取成功", Result = true, DBDataSet = dtset }));
    }

    /// <summary>
    /// 动态获取工艺
    /// </summary>
    /// <param name="context"></param>
    public void GetWorkFlowListDatas(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        CurrentUserInfo m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
        string productinfo = context.Request.Form["productName"].ToString();
        DataTable wfdata = new DataTable();
        Dictionary<string, string> para = new Dictionary<string, string>();
        para["ProductName"] = productinfo.Substring(0, productinfo.IndexOf(":"));
        para["ProductRev"] = productinfo.Substring(productinfo.IndexOf(":") + 1);
        para["FactoryID"] = m_UserInfo.FactoryID;
        wfdata = m_CommonObj.GetWorkflowInfoWithOtherAndSubByProductInfo(para, false, true);
        if (wfdata.Rows.Count == 0)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Message = "件号没有关联工艺", Result = false }));
            return;
        }
        int index = 0;
        foreach (DataRow item in wfdata.Rows)
        {
            if (!string.IsNullOrWhiteSpace(item["WorkflowID"].ToString()) && !string.IsNullOrWhiteSpace(item["WorkflowName"].ToString()))
            {
                continue;
            }
            else
            {
                index += 1;
            }
            if (index == wfdata.Rows.Count)
            {
                result.Result = false;
                result.Message = "件号关联的工艺信息不完善";
                break;
            }
        }
        if (result.Result)
        {
            result.DBTable = wfdata;
        }
        context.Response.Write(JsonConvert.SerializeObject(result));

    }

    /// <summary>
    /// 动态获取工序下拉列表
    /// </summary>
    /// <param name="context"></param>
    public void GetStepListDatas(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        CurrentUserInfo m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
        string workFlowID = context.Request.Form["workFlowID"].ToString();
        DataTable stepTable = m_CommonObj.GetWorkFlowSetpsByWorkflowID(workFlowID);//获取工序列表
        if (stepTable.Rows.Count == 0)
        {
            result.Result = false;
            result.Message = "没有工序数据";
        }
        if (result.Result)
        {
            //开始做工序验证
            Dictionary<string, string> para = new Dictionary<string, string>();
            para.Add("WorkflowID", workFlowID);
            para.Add("ChildWorkflow", "1");
            para.Add("GetFactoryValue", "");
            string childerStepIDs = "";//子工艺工序IDs  
            DataTable childwrokflowdt = m_CommonObj.GetWorkFlowSetpsDetailByWorkflowID(para);//获取子工艺
            childwrokflowdt.Columns.Add("CHILDWORKFLOW");
            foreach (DataRow r in childwrokflowdt.Rows)
            {
                if (r["WORKFLOWNAME"].ToString().Contains("空子工艺"))
                {
                    if (childwrokflowdt.Columns.Contains("factoryvalue"))
                    {
                        if (r["factoryvalue"].ToString() == "是")
                        {
                            result.Result = false;
                            result.Message = "子工艺为空子工艺，不允许开卡";
                            break;
                        }
                    }
                }
                childerStepIDs += r["WORKFLOWSTEPID"].ToString() + "，";
                r["CHILDWORKFLOW"] = r["WORKFLOWSTEPNAME"].ToString() + "(" + r["WORKFLOWNAME"].ToString() + ")";
            }
            if (result.Result)
            {
                childerStepIDs = childerStepIDs.Trim('，');
                string strValue_ = m_CommonObj.GetFatoryAttributes(m_UserInfo.FactoryID, "工序关联工区班组"); //获取工厂是否多人派工 燃烧不修改不可以派给其他班组
                if (strValue_ == "是")
                {
                    DataTable dt_ = m_CommonObj.GetWorkFlowStepsWithSpceControlCodeAndCheckStep(workFlowID, m_UserInfo.FactoryID); //获取固定转工固定外委以及检验序工序
                    string NotthisFactoryStepIDs = "";//不用检验的工序，即固定外委或固定转工的工序  
                    foreach (DataRow dr in dt_.Rows)
                    {
                        NotthisFactoryStepIDs += dr["WORKFLOWSTEPID"].ToString() + "，";
                    }
                    NotthisFactoryStepIDs = NotthisFactoryStepIDs.Trim('，');
                    foreach (DataRow item in stepTable.Rows)
                    {
                        if (NotthisFactoryStepIDs.Contains(item["WORKFLOWSTEPID"].ToString()) || childerStepIDs.Contains(item["WORKFLOWSTEPID"].ToString()))
                        {
                            continue;
                        }
                        else
                        {
                            if (!stepTable.Columns.Contains("WORKCENTERID") || string.IsNullOrWhiteSpace(item["WORKCENTERID"].ToString()))
                            {
                                result.Result = false;
                                result.Message = "工序 " + item["WORKFLOWSTEPNAME"].ToString() + " 的工区信息没有维护";
                                break;
                            }
                        }
                    }
                }
            }
            if (result.Result)
            {
                result.DBTable = stepTable;
            }
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 动态获取班组下拉数据
    /// </summary>
    /// <param name="context"></param>
    public void GetTeams(HttpContext context)
    {
        DataTable dt_team = m_CommonObj.GetTeam(context.Request.Form["workcenterID"].ToString());
        context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Message = "获取成功", Result = true, DBTable = dt_team }));
    }

    /// <summary>
    /// 动态获取机型列表数据
    /// </summary>
    /// <param name="context"></param>
    public void GetProductFamily(HttpContext context)
    {
        Dictionary<string, string> para = new Dictionary<string, string>();
        para.Add("FamilyType", context.Request.Form["FamilyType"].ToString());
        DataTable pfdt = m_CommonObj.GetProductFamily(para);
        context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Message = "获取成功", Result = true, DBTable = pfdt }));
    }

    /// <summary>
    /// 保存多订单批次数据
    /// </summary>
    /// <param name="context"></param>
    public void SaveContainerData(HttpContext context)
    {
        CurrentUserInfo m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
        if (m_UserInfo == null)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Message = "系统缓存已过期，请刷新页面", Result = false }));
            return;
        }
        List<ContainerViewModel> containerList = new List<ContainerViewModel>();
        List<ProductFamily> productFamily = new List<ProductFamily>();
        containerList = JsonConvert.DeserializeObject<List<ContainerViewModel>>(context.Request.Form["containerDatas"].ToString());//多订单批次信息
        if (containerList == null || containerList.Count == 0)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Message = "未有订单数据", Result = false }));
            return;
        }
        //productFamily = JsonConvert.DeserializeObject<List<ProductFamily>>(context.Request.Form["famliyDatas"].ToString());//机型列表
        //if (productFamily == null || productFamily.Count == 0)
        //{
        //    context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Message = "未选择机型", Result = false }));
        //    return;
        //}
        //
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "开卡成功" };
        foreach (ContainerViewModel item in containerList)
        {
            if (item.ContainerName.Contains(" "))
            {
                result.Result = false;
                result.Message = "批次号不能有空格";
                break;
            }
        }
        if (result.Result)
        {
            string successContainer = "";//成功的批次（只针对部分成功的提示）
            //开始建卡
            foreach (ContainerViewModel item in containerList)
            {
                item.ContainerQty = item.Qty - item.ConNumber;
                ContainerStartInfo containerBaseInfo = FillContainerInfo(item, m_UserInfo);

                //填充子工序
                containerBaseInfo.ChildList = null;
                if (item.ContainerType == "3") //如果是批量子序号，才填充
                {
                    containerBaseInfo.ChildList = FillChildContainerInfo(containerBaseInfo);
                }
                //填充机型
                //string strFamily = string.Empty;
                //Dictionary<int, string> listFamily = new Dictionary<int, string>();
                //for (int i = 0; i < productFamily.Count; i++)
                //{
                //    strFamily += " " + productFamily[i].ProductFamilyName;
                //    listFamily.Add(i + 1, productFamily[i].ProductFamilyName);
                //}
                //containerBaseInfo.MfgBatch = string.Format("型别：{0} |", strFamily.Trim());
                //containerBaseInfo.ProductFamilyList = listFamily;
                string sql = string.Format("SELECT NVL(m.productfamilyname,'-') productfamilyname FROM mfgorder m WHERE m.mfgordername = '{0}'", containerBaseInfo.MfgOrder);
                string orderProductFamily = DatabaseAccess.DBUtility.DatabaseHelper.Query_ReturnDatTable(sql).Rows[0]["productfamilyname"].ToString();
                if (orderProductFamily.Contains(","))
                {
                    string[] strPF = orderProductFamily.Split(',');
                    string batch = string.Empty;
                    Dictionary<int, string> pfList = new Dictionary<int, string>();
                    for (var i = 0; i <= strPF.Length; i++)
                    {
                        batch += string.Format("{0} ", strPF[i]);
                        pfList.Add(i + 1, strPF[i]);
                    }
                    containerBaseInfo.MfgBatch = string.Format("型别：{0}|", batch);
                    containerBaseInfo.ProductFamilyList = pfList;
                }
                else
                {
                    containerBaseInfo.MfgBatch = string.Format("型别：{0} |", orderProductFamily);
                    containerBaseInfo.ProductFamilyList = new Dictionary<int, string>() { { 1, orderProductFamily } };
                }
                //扩展属性
                containerBaseInfo.AttributeList = AddContainerAttribute(containerBaseInfo, item);
                //增加设置同工艺只校对一次 
                string msg = "";
                result.Result = ypCommon.SetSameWorkflowProofreadContainer(ref containerBaseInfo, ref msg);
                if (!result.Result)
                {
                    result.Message = "批次：" + containerBaseInfo.ContainerName + "开卡失败，原因：" + msg;
                    break;
                }
                //开卡
                ResultStatus res = m_ContainerObj.StartContainer(containerBaseInfo);
                if (res.IsError)
                {
                    result.Result = false;
                    result.Message = res.Message.ToString().Replace("Container", "批次：").Replace("already exists", "已存在");
                    break;
                }
                successContainer += "批次：" + containerBaseInfo.ContainerName + ",";

                //批量创建锻件批次 add zhunan 2025.9.16
                Dictionary<string, object> para = new Dictionary<string, object>();
                para["isselfmfg"] = containerBaseInfo.IsSelfMfg.ToString() == "True" ? "1" : "0";
                para["togetherflag"] = containerBaseInfo.ContainerName;
                para["fullname"] = m_UserInfo.FullName;
                para["employeeid"] = m_UserInfo.EmployeeID;
                wms.SaveMaterialApplyJson(para);
            }
            if (!result.Result && !string.IsNullOrWhiteSpace(successContainer))
            {
                result.Message = successContainer.Trim(',') + "开卡成功！ " + result.Message;
            }
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 填充批次信息
    /// </summary>
    /// <param name="containerView"></param>
    /// <returns></returns>
    private ContainerStartInfo FillContainerInfo(ContainerViewModel containerView, CurrentUserInfo userInfo)
    {
        ContainerStartInfo containerBaseInfo = new ContainerStartInfo();
        containerBaseInfo.ContainerName = containerView.ContainerName;
        containerBaseInfo.YpContainerNo = containerView.ContainerNo;
        containerBaseInfo.YpHeatNo = containerView.HeatNo;
        containerBaseInfo.YpContainerCardNo = containerView.ContainerCardNo;
        containerBaseInfo.Qty = containerView.ContainerQty;
        containerBaseInfo.MfgOrder = containerView.MfgOrderName;
        containerBaseInfo.MonthPlan = "";//月度计划
        containerBaseInfo.IsSelfMfg = containerView.MaterialType;
        FillContainerDefaultInfo(ref containerBaseInfo, userInfo.FactoryID);
        containerBaseInfo.TogetherFlag = containerView.ContainerName;
        containerBaseInfo.Factory = userInfo.Factory;
        containerBaseInfo.CheckTechnique = containerView.Technique;
        containerBaseInfo.UOM = containerView.UOMFieldName;
        containerBaseInfo.WorkCenter = containerView.WorkCenterName;
        containerBaseInfo.Team = containerView.Team;
        containerBaseInfo.StartEmployee = userInfo.EmployeeName;
        containerBaseInfo.BeginStep = containerView.StartWorkflowStepName;
        containerBaseInfo.ProductName = containerView.ProductName.Substring(0, containerView.ProductName.IndexOf(":"));
        containerBaseInfo.ProductRevision = containerView.ProductName.Substring(containerView.ProductName.IndexOf(":") + 1);
        containerBaseInfo.ProductuseROR = false;
        containerBaseInfo.MfgWorkflowName = containerView.WorkflowName.Substring(0, containerView.WorkflowName.IndexOf(":"));
        containerBaseInfo.MfgWorkflowRevision = containerView.WorkflowName.Substring(containerView.WorkflowName.IndexOf(":") + 1, containerView.WorkflowName.LastIndexOf("(") - containerView.WorkflowName.IndexOf(":") - 1);
        containerBaseInfo.MfgWorkflowuseROR = false;
        containerBaseInfo.Comment = containerView.ContainerComments;
        containerBaseInfo.PlannedStartDate = DateTime.Parse(containerView.PlannedStartDate).ToString("yyyy-MM-ddTHH:mm:ss");
        containerBaseInfo.PlannedCompletionDate = DateTime.Parse(containerView.PlannedCompletionDate).ToString("yyyy-MM-ddTHH:mm:ss");
        containerBaseInfo.ContainerType = containerView.ContainerType;
        containerBaseInfo.MilitaryType = containerView.MilitaryType;
        containerBaseInfo.YpContainerType = containerView.YpContainerType;
        containerBaseInfo.QualificationQty = "1";//add:Wangjh 20220622
        ServerHostInfo serverInfo = new ServerHostInfo();
        serverInfo.UserName = userInfo.APIUserName;
        serverInfo.Password = userInfo.APIPassword;
        containerBaseInfo.ServerHostInfo = serverInfo;
        return containerBaseInfo;
    }

    /// <summary>
    /// 填充批次默认信息
    /// </summary>
    /// <param name="containerBaseInfo"></param>
    /// <param name="factoryId"></param>
    private void FillContainerDefaultInfo(ref ContainerStartInfo containerBaseInfo, string factoryId)
    {
        DataTable levelAttributes = m_CommonObj.GetFatoryAttributes(factoryId);
        DataRow[] datarows = levelAttributes.Select("USERATTRIBUTENAME='默认所有者'");
        string strOwner = "";
        if (datarows.Length > 0)
        {
            strOwner = datarows[0]["ATTRIBUTEVALUE"].ToString();
        }
        datarows = levelAttributes.Select("USERATTRIBUTENAME='默认层级'");
        string strLevel = "";
        if (datarows.Length > 0)
        {
            strLevel = datarows[0]["ATTRIBUTEVALUE"].ToString();
        }
        string strStart = "";
        if (string.IsNullOrWhiteSpace(containerBaseInfo.MfgOrder.ToString()))
        {
            datarows = levelAttributes.Select("USERATTRIBUTENAME='无订单开始原因'");
        }
        else
        {
            datarows = levelAttributes.Select("USERATTRIBUTENAME='订单开始原因'");
        }
        if (datarows.Length > 0)
        {
            strStart = datarows[0]["ATTRIBUTEVALUE"].ToString();
        }

        containerBaseInfo.StartReason = strStart;
        containerBaseInfo.Level = strLevel;
        containerBaseInfo.Owner = strOwner;
        string test = containerBaseInfo.IsSelfMfg.ToString();
        if (containerBaseInfo.IsSelfMfg.ToString() == "True")
        {
            datarows = levelAttributes.Select("USERATTRIBUTENAME='自投料流程'");
        }
        else
        {
            datarows = levelAttributes.Select("USERATTRIBUTENAME='领料流程'");
        }
        if (datarows.Length > 0)
        {
            string[] strWorkflows = datarows[0]["ATTRIBUTEVALUE"].ToString().Split('：');
            containerBaseInfo.WorkflowName = strWorkflows.First();
            containerBaseInfo.WorkflowRevision = strWorkflows.Last();
            containerBaseInfo.WorkflowuseROR = false;
        }
    }

    /// <summary>
    /// 填充子批次
    /// </summary>
    /// <param name="containerBaseInfo"></param>
    /// <returns></returns>
    private DataTable FillChildContainerInfo(ContainerStartInfo containerBaseInfo)
    {
        DataTable childDT = new DataTable();
        childDT.Columns.Add("ContainerName");
        childDT.Columns.Add("Qty");
        childDT.Columns.Add("ChildBeginStep");
        childDT.Columns.Add("TogetherFlag");
        childDT.Columns.Add("QualificationNum");
        childDT.Columns.Add("YpContainerType");
        int qty = int.Parse(containerBaseInfo.Qty.ToString());
        for (int i = 1; i <= qty; i++)
        {
            DataRow dr = childDT.NewRow();
            dr["ContainerName"] = containerBaseInfo.ContainerName + i.ToString().PadLeft(2, '0');
            dr["Qty"] = 1;
            dr["ChildBeginStep"] = containerBaseInfo.BeginStep;
            dr["TogetherFlag"] = containerBaseInfo.TogetherFlag;
            dr["QualificationNum"] = i.ToString().PadLeft(2, '0');
            dr["YpContainerType"] = containerBaseInfo.YpContainerType;
            childDT.Rows.Add(dr);
        }
        return childDT;
    }

    /// <summary>
    /// 添加流水卡扩展属性
    /// </summary>
    /// <param name="containerInfo"></param>
    /// <param name="containerView"></param>
    /// <returns></returns>
    private DataTable AddContainerAttribute(ContainerStartInfo containerInfo, ContainerViewModel containerView)
    {
        DataTable attributeDt = new DataTable();
        attributeDt.Columns.Add("ContainerName");
        attributeDt.Columns.Add("Level");
        attributeDt.Columns.Add("Name");
        attributeDt.Columns.Add("Value");
        DataRow row = attributeDt.NewRow();
        SetAttributeRow(ref row, containerInfo, "CheckTechnique", containerView.Technique);
        attributeDt.Rows.Add(row);
        //if (!string.IsNullOrWhiteSpace(containerInfo.MonthPlan.ToString()))
        //{
        //    row = attributeDt.NewRow();
        //    SetAttributeRow(ref row, containerInfo, "monthPlanName", containerInfo.MonthPlan.ToString());
        //}
        row = attributeDt.NewRow();
        SetAttributeRow(ref row, containerInfo, "BeginStep", containerInfo.BeginStep.ToString());
        attributeDt.Rows.Add(row);

        //增加机加批次平行作业工序获取
        string pxzySpecNo = "", pxzyOrderNo = "";//平行作业工序,平行作业单号
        if (containerView.YpContainerType == "2")
        {
            DataTable dtMache = ypCommon.GetMacheExtraWorkStep(containerInfo);
            if (dtMache.Rows.Count > 0)
            {
                pxzySpecNo = dtMache.Rows[0]["pxzyspecno"].ToString();
                pxzyOrderNo = dtMache.Rows[0]["ypmacheextraworkno"].ToString();
            }
        }
        if (containerView.MaterialType == "0") //如果是领料类型
        {
            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "材料牌号", "");
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "实发数/顺序号", "");
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "熔炉号母", "");
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "检验编号", "");
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "库房保管", "");
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "代料牌号", "");
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "代料规格", "");
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "代料单号", "");
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "平行作业单号", pxzyOrderNo);
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "平行作业工序", pxzySpecNo);
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "器材检验", "");
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "顾客代表", "");
            attributeDt.Rows.Add(row);

            row = attributeDt.NewRow();
            SetAttributeRow(ref row, containerInfo, "不合格审理单号", "");
            attributeDt.Rows.Add(row);
        }
        else
        {
            if (containerView.YpContainerType == "2") //如果是机加类型且不领料
            {
                row = attributeDt.NewRow();
                SetAttributeRow(ref row, containerInfo, "平行作业单号", pxzyOrderNo);
                attributeDt.Rows.Add(row);

                row = attributeDt.NewRow();
                SetAttributeRow(ref row, containerInfo, "平行作业工序", pxzySpecNo);
                attributeDt.Rows.Add(row);

                row = attributeDt.NewRow();
                SetAttributeRow(ref row, containerInfo, "器材检验", "");
                attributeDt.Rows.Add(row);
            }
        }
        return attributeDt;
    }
    /// <summary>
    /// 设置属性行
    /// </summary>
    /// <param name="row"></param>
    /// <param name="containerInfo"></param>
    /// <param name="attributeName"></param>
    /// <param name="attributeValue"></param>
    private void SetAttributeRow(ref DataRow row, ContainerStartInfo containerInfo, string attributeName, string attributeValue)
    {
        row["ContainerName"] = containerInfo.ContainerName;
        row["Level"] = containerInfo.Level;
        row["Name"] = attributeName;
        row["Value"] = attributeValue;
    }

    /// <summary>
    /// 页面填写的批次信息
    /// </summary>
    public class ContainerViewModel
    {
        /// <summary>
        /// 订单id
        /// </summary>
        public string MfgOrderID { get; set; }
        /// <summary>
        /// 订单号
        /// </summary>
        public string MfgOrderName { get; set; }
        /// <summary>
        /// 零件id
        /// </summary>
        public string ProductID { get; set; }
        /// <summary>
        /// 零件号
        /// </summary>
        public string ProductName { get; set; }

        /// <summary>
        /// 工艺流程id
        /// </summary>
        public string WorkflowID { get; set; }
        /// <summary>
        /// 工艺流程
        /// </summary>
        public string WorkflowName { get; set; }

        /// <summary>
        /// 订单类型id
        /// </summary>
        public string OrderTypeID { get; set; }
        /// <summary>
        /// 单位id
        /// </summary>
        public string UOMField { get; set; }
        /// <summary>
        /// 单位值
        /// </summary>
        public string UOMFieldName { get; set; }
        /// <summary>
        /// 领料类型
        /// </summary>
        public string MaterialType { get; set; }
        /// <summary>
        /// 计划开始日期
        /// </summary>
        public string PlannedStartDate { get; set; }
        /// <summary>
        /// 计划结束日期
        /// </summary>
        public string PlannedCompletionDate { get; set; }
        /// <summary>
        /// 工艺员
        /// </summary>
        public string Technique { get; set; }
        /// <summary>
        /// 工艺员全名
        /// </summary>
        public string TechniqueName { get; set; }

        /// <summary>
        /// 主制班组
        /// </summary>
        public string Team { get; set; }
        /// <summary>
        /// 主制工区
        /// </summary>
        public string WorkCenter { get; set; }
        /// <summary>
        /// 主制工区名
        /// </summary>
        public string WorkCenterName { get; set; }
        /// <summary>
        /// 数量
        /// </summary>
        public int ContainerQty { get; set; }
        /// <summary>
        /// 批次号
        /// </summary>
        public string ContainerName { get; set; }
        /// <summary>
        /// 批次类型
        /// </summary>
        public string ContainerType { get; set; }
        /// <summary>
        /// 开始工序
        /// </summary>
        public string StartWorkflowStep { get; set; }
        /// <summary>
        /// 开始工序名
        /// </summary>
        public string StartWorkflowStepName { get; set; }
        /// <summary>
        /// 批次编号(锻批号)
        /// </summary>
        public string ContainerNo { get; set; }
        /// <summary>
        /// 热处理顺序号
        /// </summary>
        public string HeatNo { get; set; }
        /// <summary>
        /// 卡片号
        /// </summary>
        public string ContainerCardNo { get; set; }
        /// <summary>
        /// 订单数
        /// </summary>
        public int Qty { get; set; }
        /// <summary>
        /// 已开卡数
        /// </summary>
        public int ConNumber { get; set; }
        /// <summary>
        /// 客户类型
        /// </summary>
        public string MilitaryType { get; set; }
        /// <summary>
        /// 叶片批次类型
        /// </summary>
        public string YpContainerType { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string ContainerComments { get; set; }
    }

    /// <summary>
    /// 机型信息
    /// </summary>
    public class ProductFamily
    {
        /// <summary>
        /// 机型
        /// </summary>
        public string ProductFamilyName { get; set; }
    }
}